import { UserProfilesAPI } from '@/request/api'
export default {
    //1.设置命名空间
    namespaced: true,
    //贡献数据
    state: {
        userInfo: {
            //昵称
            nickName: "",
            //积分 鸡腿数
            coin: "",
            //头像
            headImg: require("@/assets/img/userImg.f8bbec5e.png"),
        },
        //购物数量
        cartTotal: 0
    },
    mutations: {
        //修改是否显示用户信息
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        //初始化登录信息
        initUserInfo(state) {
            state.userInfo = {
                //昵称
                nickName: "",
                //积分 鸡腿数
                coin: "",
                //头像
                headImg: require("@/assets/img/userImg.f8bbec5e.png"),
            }
            state.cartTotal = 0;
        }
    },
    actions: {
        async asyncChangeUserInfo(context) {
            //1.请求用户信息
            let user = await UserProfilesAPI();
            //2.调用mutations更新用户信息
            context.commit("changeUserInfo", user.data)
        }
    }
}